﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

namespace PM.PMBusiness
{
    /// <summary>
    /// projectpaused 的摘要说明
    /// </summary>
    public class projectpaused
    {
        public projectpaused()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        /// <summary>
        /// 获取一个项目计划的相关信息
        /// </summary>
        /// <param name="projectid">项目的表编号</param>
        /// <returns>返回实体类project</returns>
        public PM.Model.ProjectPlan getAProject(string projectid)
        {
            PM.Model.ProjectPlan APlan = new PM.Model.ProjectPlan();
            string sqlstr = "select id,plancode,plevel,ptype,opendate,closedate,btnname from View_ProjectPlan  where id="+projectid;
            SqlDataReader result = PM.Code.DAL.DbHelper.ExecuteDataReaderBySql(sqlstr.ToString());
            if (result.HasRows)
            {
                if (result.Read())
                {
                    APlan.id = Int32.Parse(result[0].ToString());
                    APlan.plancode = result[1].ToString();
                    APlan.plevel = result[2].ToString();
                    APlan.ptype = result[3].ToString();
                    APlan.opendate = DateTime.Parse(result[4].ToString());
                    APlan.closedate = DateTime.Parse(result[5].ToString());
                    APlan.typename = result[6].ToString();
                }
                result.Close();
            }
            return APlan;
        }
        /// <summary>
        /// 获取与项目计划相关的教师已提交的文件
        /// </summary>
        /// <param name="projectid">项目编号</param>
        /// <returns>返回sqldatareader</returns>
        public SqlDataReader getProjectFiles(string plancode)
        {
            PM.Model.ProjectPlan APlan = new PM.Model.ProjectPlan();
            string sqlstr = "select id,[type],pcode,pmanager,depart from View_Projects  where pcode='" + plancode+"'";
            SqlDataReader result = PM.Code.DAL.DbHelper.ExecuteDataReaderBySql(sqlstr.ToString());
            return result;
        }
        /// <summary>
        /// 获取与中断的项目计划
        /// </summary>
        /// <returns>返回sqldatareader</returns>
        public SqlDataReader getPausedProject()
        {
            PM.Model.ProjectPlan APlan = new PM.Model.ProjectPlan();
            string sqlstr = "select id,plancode,btnname from View_ProjectPlan  where pstatus='中断'";
            SqlDataReader result = PM.Code.DAL.DbHelper.ExecuteDataReaderBySql(sqlstr.ToString());
            return result;
        }
        /// <summary>
        /// 绑定相关的下拉框
        /// </summary>
        /// <param name="ddl1">要绑定的下拉框</param>
        /// <param name="typeid">计划的项目类别编号</param>
        /// <param name="level">计划的项目级别</param>
        /// <param name="ptype">计划的项目类型</param>
        public void bindTransType(DropDownList ddl1,string typeid,string level,string ptype)
        {
            StringBuilder sqlstr = new StringBuilder("select opendate,plancode from View_ProjectPlan");
            sqlstr.Append(" where type=").Append(typeid).Append(" and plevel='").Append(level).Append("' and ptype='").Append(ptype).Append("' and opendate>'").Append(DateTime.Now.ToString()).Append("'");
            SqlDataReader myreader = PM.Code.DAL.DbHelper.ExecuteDataReaderBySql(sqlstr.ToString());
            while(myreader.Read())
            {
                ddl1.Items.Add(new ListItem(myreader[0].ToString(),myreader[1].ToString()));
            }
            myreader.Close();
        }
        /// <summary>
        /// 更新项目的申报计划编号（附件转移）
        /// </summary>
        /// <param name="oldplanid">原来的计划编号</param>
        /// <param name="newplanid">目标计划编号</param>
        /// <returns>返回受影响的行数</returns>
        public int Update_Planid(string oldplanid, string newplanid)
        {
            string sqlstr = "update Bus_Project set pcode='"+newplanid+"' where pcode='"+oldplanid+"'";
            return PM.Code.DAL.DbHelper.ExecuteSql(sqlstr);
        }
        /// <summary>
        /// 删除一项项目计划
        /// </summary>
        /// <param name="oldplanid">计划编号</param>
        /// <returns>返回受影响的行数</returns>
        public int Delete_Planid(string planid)
        {
            string sqlstr = "delete from Bus_Project where pcode='" + planid + "'";
            return PM.Code.DAL.DbHelper.ExecuteSql(sqlstr);
        }
    }
}
